using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using RFS.BizLogic.PaiShi.Ports;
using RFS.WPF.StartUp;
using RFS.WPF.utils;

namespace RFS.WPF.Views.Settings
{
    public partial class Price : System.Windows. Window
    {
        public Price()
        {
            InitializeComponent();



            Task.Run(() =>
            {
                1.UseUIThread(() =>
                {

                    CDate.SelectedDate = DateTime.Today.AddDays(-2);

                });
            });

        }
        
        void Runb(Action act)
        {
            
            Cursor= Cursors.Wait;
            try
            {
                act?.Invoke();
            }
            finally
            {
                Cursor= Cursors.Arrow;

            }
            
        }

        

        private void CDate_OnSelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            Runb(() =>
            {
                1.UseUIThread(() =>
                {

                        var ds=ViewStarter.Ins.Get<IPriceManagerPort>().GetPriceItems(CDate.SelectedDate.Value );

                        gFH.ItemsSource = ds;                
                    
                });

            });

        }

        private void ButtonBasePre_OnClick(object sender, RoutedEventArgs e)
        {
            
             CDate.SelectedDate=CDate.SelectedDate.Value.AddDays(-1);
        }

        private void ButtonBaseNext_OnClick(object sender, RoutedEventArgs e)
        {
            
            if (CDate.SelectedDate.Value>=DateTime.Today) return;
            CDate.SelectedDate=   CDate.SelectedDate.Value.AddDays(1)  ;

        }
    }
}